

console.log("sheindetail pre")


chrome.runtime.onMessage.addListener(async (msg, sender) => {
    console.log(msg)
    var url = "https://www.shein.com.hk"+ msg.data.url+"?src_identifier=fc=Office%20&%20School%20Supplies`sc=Office%20&%20School%20Supplies`tc=0`oc=0`ps=tab14navbar14`jc=itemPicking_017185552&src_module=topcat&src_tab_page_id=page_select_class1738490304354&mallCode=1&pageListType=4&imgRatio=1-1&bid="+msg.data.id+"&auto_get=true";
    console.log(url)
    // 调用函数并提供目标链接
    addAndClickLink(url);
})




function simulateClick(element) {
    // 创建并初始化鼠标事件
    const clickEvent = new MouseEvent('click', {
        bubbles: true,
        cancelable: true,
        view: window
    });

    // 触发事件
    element.dispatchEvent(clickEvent);
}

function addAndClickLink(url) {
    // 创建一个新的a标签
    const link = document.createElement('a');
    link.href = url;
    link.innerText = "Click me";
    link.target = '_blank';  // 设置为在新标签页打开
    link.style.position = 'absolute'; // 确保链接可见
    link.style.top = '10px'; // 定位链接的位置
    link.style.left = '10px'; // 定位链接的位置
    document.body.appendChild(link);

    // 模拟用户点击
    setTimeout(() => {
        simulateClick(link);
        // 移除a标签
        setTimeout(() => {
            document.body.removeChild(link);
        }, 1000); // 等待一秒后再移除
    }, 1100); // 等待一秒后再点击
}






